package cn.jbt.api.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.jbt.api.admin.annotation.Log;
import cn.jbt.api.admin.entity.SysMenu;
import cn.jbt.api.admin.service.ISysMenuService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/system/menu")
@Slf4j
@AllArgsConstructor
public class SysMenuController {

    private final ISysMenuService iSysMenuService;

    @PostMapping("/list")
    @SaCheckPermission("system:menu:list")
    @Log(bizType = "查询", bizName = "查询菜单信息列表")
    public List<SysMenu> getAll(@RequestBody SysMenu sysMenu) {
        return iSysMenuService.getAll(sysMenu);
    }

    @PostMapping("/add")
    @SaCheckPermission("system:menu:add")
    @Log(bizType = "新增", bizName = "新增菜单信息")
    public SysMenu add(@Valid @RequestBody SysMenu sysMenu) {
        return iSysMenuService.add(sysMenu);
    }

    @PostMapping("/edit")
    @SaCheckPermission("system:menu:edit")
    @Log(bizType = "编辑", bizName = "编辑菜单信息")
    public SysMenu edit(@Valid @RequestBody SysMenu sysMenu) {
        return iSysMenuService.edit(sysMenu);
    }

    @PostMapping("/del")
    @SaCheckPermission("system:menu:del")
    @Log(bizType = "删除", bizName = "删除菜单信息")
    public void del(@NotEmpty @RequestBody List<Long> ids) {
        iSysMenuService.del(ids);
    }

}
